function PyResult() {
    this.form = this.InitForm();
    this.table = this.InitTableByBt();
}

PyResult.prototype.InitForm = function () {
    var form;
    $("#year").val($("#hidyear").val());
    layui.use('form', function () {
        form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    });
    return form;
}

var _table;
PyResult.prototype.InitTableByBt = function () {
    var table;
    var _this = this;
    var index = layer.load();
    layui.use('table', function () {
        var quarter = $('input[name="quarter"]:checked ').val();
        var month1 ="一月";
        var month2 ="二月";
        var month3 ="三月";
        if(quarter ==2){month1="四月";month2="五月";month3="六月"}
        if(quarter ==3){month1="七月";month2="八月";month3="九月"}
        if(quarter ==4){month1="十月";month2="十一月";month3="十二月"}

        table = layui.table;
        table.render({
            height: $(window).height() - 150
            , elem : '#list'
            ,id: 'uatmzpdsummary'
            , url: 'get_work_season_list' // 数据接口
            ,page : true // 开启分页
            ,limit : 40
            ,limits:[20,40,80,100]
            , method: "post"
            ,cols: [
                    [
                        {title : '扣减情况',align : 'center',colspan: 8}
                        , {title : '增加情况',align : 'center',colspan: 4}
                    ],
                    [ // 表头
                        {field : 'realname',title : '姓名',width : 80,align : 'center',fixed: 'left'}
                        , {field:'orgname',title : '部门', width:120,align:'center'}
                        , {field : 'cardno',title : '身份证号',width : 120,align : 'center'}
                        , {field : 'downreason',title : '原因',width : 120,align : 'center'}
                        , {field : 'workpernum1',title : ''+month1+'',width : 80,align : 'center'}
                        , {field : 'workpernum2',title : ''+month2+'',width : 80,align : 'center'}
                        , {field : 'workpernum3',title : ''+month3+'',width : 80,align : 'center'}
                        , {field : 'workpernumsum',title : '加班补贴合计',width : 180,align : 'center'}
                        , {field : 'realname',title : '姓名',width : 80,align : 'center'}
                        , {field : 'cardno',title : '身份证号',width : 120,align : 'center'}
                        , {field : 'upreason',title : '原因',width : 120,align : 'center'}
                        , {field : 'upmoney',title : '金额',width : 120,align : 'center'}
                    ]
                ]
            , request: {
                type: 'post'
            }
            , where: {
                year: $("#year").val(),
                quarter: $('input[name="quarter"]:checked ').val(),
                orgid: $("#szdw").val()
            }
            , done: function (res, page, count) {
                var year = $("#year").val();
                var quarter = $('input[name="quarter"]:checked ').val();

                var orgname = $("#szdw").find("option:selected").text();
                var orgname = $.trim(orgname);
                $("#title").html(orgname+"("+year + "年第" + quarter + "季度)工作性津贴申报表");
                layer.close(index);
            }
        });
        table.on('edit(list)', function(obj){
            var day = obj.value;
            console.log(day)
        });
    })
    _table = table;
    return table;
}


PyResult.prototype.searchtable = function () {
    var quarter = $('input[name="quarter"]:checked ').val();
    var month1 ="一月";
    var month2 ="二月";
    var month3 ="三月";
    if(quarter ==2){month1="四月";month2="五月";month3="六月"}
    if(quarter ==3){month1="七月";month2="八月";month3="九月"}
    if(quarter ==4){month1="十月";month2="十一月";month3="十二月"}
    _table.reload('uatmzpdsummary', {
        cols: [
            [
                {title : '扣减情况',align : 'center',colspan: 8}
                , {title : '增加情况',align : 'center',colspan: 4}
            ],
            [ // 表头
                {field : 'realname',title : '姓名',width : 80,align : 'center',fixed: 'left'}
                , {field:'orgname',title : '部门', width:120,align:'center'}
                , {field : 'cardno',title : '身份证号',width : 120,align : 'center'}
                , {field : 'downreason',title : '原因',width : 120,align : 'center'}
                , {field : 'workpernum1',title : ''+month1+'',width : 80,align : 'center'}
                , {field : 'workpernum2',title : ''+month2+'',width : 80,align : 'center'}
                , {field : 'workpernum3',title : ''+month3+'',width : 80,align : 'center'}
                , {field : 'workpernumsum',title : '加班补贴合计',width : 180,align : 'center'}
                , {field : 'realname',title : '姓名',width : 80,align : 'center'}
                , {field : 'cardno',title : '身份证号',width : 120,align : 'center'}
                , {field : 'upreason',title : '原因',width : 120,align : 'center'}
                , {field : 'upmoney',title : '金额',width : 120,align : 'center'}
            ]
        ],
        where: {
            year: $("#year").val(),
            quarter: $('input[name="quarter"]:checked ').val(),
            orgid: $("#szdw").val()
        }
    });
}


PyResult.prototype.excle = function () {
    // top.ShowZheZhao();
    // var tabledataJson = this.table.cache;
    // var year = $("#year").val();
    // var quarter = $('input[name="quarter"]:checked ').val();
    // var orgname = $.trim($("#szdw").find("option:selected").text());
    // tabledataJson['yearid'] = year;
    // tabledataJson['quarter'] = quarter;
    // tabledataJson['orgname'] = orgname;
    // tabledataJson = JSON.stringify(tabledataJson);
    // tabledataJson = tabledataJson.replace(/LAY_TABLE_INDEX/g, 'lay_TABLE_INDEX');
    // $.ajax({
    //     type: "POST",
    //     url: "export_season_outwork",
    //     contentType: 'application/json',
    //     data: tabledataJson,
    //     beforeSend: function (XHR) {
    //
    //     },
    //     success: function (data) {
    //         data = eval('(' + data + ')');
    //         if (data.result > 0) {
    //             //top.mylayui.msg('导出成功', {icon: 1});
    //             window.open(data.msg, '_self');
    //         }
    //         else {
    //             top.mylayui.msg(data.msg, {icon: 0});
    //         }
    //         top.ShowZheZhao();
    //     },
    //     complete: function (XHR) {
    //         top.mylayui.closeAll('loading');
    //     },
    //     error: function () {
    //
    //     }
    // });

    top.ShowZheZhao();
    var year = $("#year").val();
    var quarter = $('input[name="quarter"]:checked ').val();
    var orgid = $("#szdw").val();

    $.ajax({
        type: "POST",
        url: "export_excel",
        data: {
            year: year,
            quarter:quarter,
            orgid: orgid
        },
        beforeSend: function (XHR) {

        },
        success: function (data) {
            data = eval('(' + data + ')');
            if (data.result > 0) {
                window.open(data.msg, '_self');
            }
            else {
                top.mylayui.msg(data.msg, {icon: 0});
            }
            top.ShowZheZhao();

        },
        complete: function (XHR) {
            top.mylayui.closeAll('loading');
        },
        error: function () {

        }
    });
}


var vWorkSeasonzpd = null;
$(function () {
    vWorkSeasonzpd = new PyResult();
})